package yunjiao.javatutorials.mq.component;

import com.github.javafaker.Faker;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import yunjiao.javatutorials.mq.model.Order;

import java.math.BigDecimal;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 订单数据生成
 *
 * @author yangyunjiao
 */
@Component
@RequiredArgsConstructor
public class RandomOrderSupplier implements Supplier<Order> {
    private final Faker faker;

    @Override
    public Order get() {
        return Order.builder().orderId(faker.internet().uuid())
                .userId(faker.internet().uuid())
                .amount(BigDecimal.valueOf(faker.number().numberBetween(10, 999)))
                .orderStatus(faker.options().option("NEW", "PAY"))
                .build();
    }

    public List<Order> get(int size) {
        return IntStream.range(0, size).mapToObj(i -> get()).collect(Collectors.toList());
    }
}
